package me.zhengjie.aop.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import me.zhengjie.business.domain.Zhsq;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;

/**
 * @author xiahongbo
 * @date 2018-11-24
 */
@Entity
@Getter
@Setter
@Table(name = "BIS_LOG")
@NoArgsConstructor
public class BisLog implements Serializable {

    @Id
    @Column(name = "BIS_LOG_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BisLogSeqGenerator")
    @SequenceGenerator(name = "BisLogSeqGenerator", sequenceName = " SEQUENCE_LOG", allocationSize = 1)
    private Long bisLogId;

    @Column(name = "BIS_LOG_USERNAME")
    @ApiModelProperty(value = "操作用户")
    private String bisLogUsername;

    @Column(name = "BIS_LOG_DESC")
    @ApiModelProperty(value = "描述")
    private String bisLogDesc;

    @Column(name = "BIS_LOG_METHOD")
    @ApiModelProperty(value = "方法名")
    private String bisLogMethod;

    @Column(name = "BIS_LOG_PARAMS")
    @ApiModelProperty(value = "参数")
    private String bisLogParams;

    @Column(name = "BIS_LOG_TYPE")
    @ApiModelProperty(value = "日志类型")
    private String bisLogType;

    @Column(name = "BIS_LOG_IP")
    @ApiModelProperty(value = "请求ip")
    private String bisLogIp;

    @Column(name = "BIS_LOG_ADDRESS")
    @ApiModelProperty(value = "地址")
    private String bisLogAddress;

    @Column(name = "BIS_LOG_BROWSER")
    @ApiModelProperty(value = "浏览器")
    private String bisLogBrowser;

    @Column(name = "BIS_LOG_TIME")
    @ApiModelProperty(value = "请求耗时")
    private Long bisLogTime;

    @Column(name = "BIS_LOG_EXCEPTION_DETAIL")
    @ApiModelProperty(value = "异常详细")
    private byte[] bisLogExceptionDetail;

    @CreationTimestamp
    @Column(name = "BIS_LOG_CREATE_TIME")
    @ApiModelProperty(value = "创建日期")
    private Timestamp bisLogCreateTime;
/*

    @Column(name = "BIS_LOG_ZHID")
    @ApiModelProperty(value = "照护ID")
    private String bisLogZhid;
*/

    @JoinColumn(name = "BIS_LOG_ZHID")
    @ManyToOne(fetch = FetchType.LAZY)
    @ApiModelProperty(value = "照护ID", hidden = true)
    @JSONField(serialize = false)
    @ToString.Exclude
    private Zhsq zhsq;

    public BisLog(String logType, Long time) {
        this.bisLogType = logType;
        this.bisLogTime = time;
    }

    public void copy(BisLog source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
    @Override
    public int hashCode() {
        return Objects.hash(bisLogId, bisLogParams);
    }
}
